//
//  UIImageView+BSExtension.m
//  Baisi
//
//  Created by 刘家俊 on 17/3/27.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "UIImageView+BSExtension.h"
#import <UIImageView+WebCache.h>
#import "UIImage+BSExtension.h"

@implementation UIImageView (BSExtension)

//这个系统的方法相对比较消耗性能，所以用上下图裁剪
//    self.imageListView.layer.cornerRadius = self.imageListView.bs_width * 0.5;
//    self.imageListView.layer.masksToBounds = YES;

/**
 返回圆形图片

 @param url 图片url
 @param placeholder 占位图
 */
- (void)bs_setCircleHeader:(NSString *)url placeholder:(NSString *)placeholder
{
    //设置占位图片(如果不设置这个方法，那么图片如果加载失败，图片是方形而不是圆形)
    UIImage *placeHolder = [UIImage bs_circleImageWith:placeholder];
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeHolder completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        //如果图片加载失败则返回（如果空占位图片有效）
        if (image == nil) {
            return ;
        }
        //返回圆形图片
        self.image = [image bs_circleImage];
    }];
}


/**
 返回方形图片

 @param url 图片url
 @param placeholder 占位图
 */
- (void)bs_setRectHeader:(NSString *)url placeholder:(NSString *)placeholder
{
    UIImage *placeHoder = [UIImage imageNamed:placeholder];
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeHoder];
}

@end
